#ifndef DICTIONARY_DOCUMENT
#define DICTIONARY_DOCUMENT

#include "Node.h"

#include <string>
#include <map>

namespace Dictionary {
	template <typename T = std::string>
	class Document {
		public :
			typedef std::map<long,Node<T> *> id_to_node_t;
			Document() : 
			     document_name(""),
					 total_term_count(-1),
					 unique_term_count(-1),
					 total_sentence_count(-1)
					 {}
			Document(const std::string &document_name) : 
					 document_name(document_name),
					 total_term_count(-1),
					 unique_term_count(-1),
					 total_sentence_count(-1)
					 {}

			~Document()  {
				std::for_each(id_to_node.begin(),id_to_node.end(),DeleteMapContainerContent<id_to_node_t::value_type>());
			}

			const std::string & get_document_name() const { return document_name; }
			long get_total_term_count() const { return total_term_count; }
			long get_unique_term_count() const { return unique_term_count;	}
			long get_total_sentence_count() const { return total_sentence_count; }
			const id_to_node_t * get_node_array() const { return &id_to_node; }
			const Sentence<T> * get_particular_sentence(long node_id,SectionType section_type,int sentence_number,int term_place) const;
			const Node<T> * get_node_by_id(long id) const;

			void set_document_name(const std::string &document_name) { this->document_name = document_name; }
			void set_total_term_count(long term_count) { this->total_term_count = term_count; }
			void set_total_sentence_count(long sentence_count) { this->total_sentence_count = sentence_count; }
			void set_unique_term_count(long unique_term_count) { this->unique_term_count = unique_term_count; }
			bool add_node(Node<T> * node);

			

		private :
			std::string document_name;
			long total_term_count;
			long total_sentence_count;
			long unique_term_count;
			id_to_node_t id_to_node;
	};
}
template <typename T>
bool Dictionary::Document<T>::add_node(Dictionary::Node<T> * node) {
	  long id = node->get_id();
	  if (id_to_node.count(id)) return false;
		id_to_node.insert(make_pair(id,node));
		return true;
	}

template <typename T>
const Dictionary::Sentence<T> * Dictionary::Document<T> :: get_particular_sentence(long node_id,Dictionary::SectionType section_type,int sentence_number,int term_place) const
{
	Node<T> *node = this->get_node_by_id(node_id);
	if (node == NULL) return NULL;
	Section<T> *section = node->get_section_by_type(section_type);
	if (section == NULL) return NULL;
}

template <typename T>
const Dictionary::Node<T> *  Dictionary::Document<T>::get_node_by_id(long id) const
{
	id_to_node_t::const_iterator node_i = id_to_node.find(id);

	return (node_i == id_to_node.end()) ? NULL : node_i->second;
}
#endif